package com.baidu.springcloud.service.impl;

import com.baidu.springcloud.service.MessageMqProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author ShiLei
 * @version v1.0
 * @date 2020-03-24 10:22
 */
@EnableBinding(Source.class) //定义消息的推送管道
public class MessageMqProviderImpl implements MessageMqProvider {

    //消息发送管道
    @Resource
    private MessageChannel output;

    @Override
    public String send() {
        String ser = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(ser).build());
        System.out.println("ser: " + ser);
        return ser;
    }
}
